<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>标记点管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {include file="public/css"/}
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-card layui-col-md12">
				<div class="layui-card-header">
					{if !$info['id']}<i class="fa fa-plus"></i> 添加门店{else}<i class="fa fa-pencil"></i> 编辑门店{/if}
					<i class="layui-icon layui-icon-close" style="font-size:18px;font-weight:bold;cursor:pointer" onclick="closeself()"></i>
				</div>
				<div class="layui-card-body" pad15>
					<div class="layui-form">
						<input type="hidden" name="info[id]" value="{$info.id}"/>
						<div class="layui-form-item">
							<label class="layui-form-label">名称：</label>
							<div class="layui-input-inline" style="width:200px">
								<input type="text" name="info[name]" lay-verify="required" lay-verType="tips" class="layui-input" value="{$info.name}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">门店主图：</label>
							<input type="hidden" name="info[pic]" id="pic" lay-verType="tips" class="layui-input" value="{$info.pic}">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" upload-input="pic" upload-preview="picPreview" onclick="uploader(this)">上传图片</button>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
							<div id="picPreview" style="float:left;padding-top:10px;padding-left:110px;clear: both;">
								<div class="layui-imgbox" style="width:100px;"><div class="layui-imgbox-img"><img src="{$info.pic}"/></div></div>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">门店图片：</label>
							<input type="hidden" name="info[pics]" value="{$info['pics']}" id="pics">
							<button style="float:left;" type="button" class="layui-btn layui-btn-primary" onclick="uploader(this,true)" upload-input="pics" upload-preview="picList" >批量上传</button>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">建议尺寸：640×640像素</div>
							<div id="picList" style="float:left;padding-top:10px;padding-left:110px;clear: both;">
								{if $info['pics']}{php}$pics = explode(',',$info['pics']);{/php}{foreach $pics as $pic}
								<div class="layui-imgbox">
									<a class="layui-imgbox-close" href="javascript:void(0)" onclick="$(this).parent().remove();getpicsval('pics','picList')" title="删除"><i class="layui-icon layui-icon-close-fill"></i></a>
									<span class="layui-imgbox-img"><img src="{$pic}"></span>
								</div>
								{/foreach}{/if}
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">摘要：</label>
							<div class="layui-input-inline" style="width:700px">
								<input type="text" name="info[subname]" class="layui-input" value="{$info.subname}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">详情：</label>
							<div class="layui-input-inline" style="width:800px">
								<script id="content" name="info[content]" type="text/plain" style="width:100%;height:500px">{$info.content}</script>
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">联系电话：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="text" id="tel" name="info[tel]" class="layui-input" value="{$info.tel}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">地址：</label>
							<div class="layui-input-inline" style="width:500px">
								<input type="text" id="address" name="info[address]" class="layui-input" value="{$info.address}">
							</div>
							<button class="layui-btn layui-btn-primary" id="searchbtn">搜索</button>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"></label>
							<div id="l-map" style="width:800px;height:500px">地图加载中...</div>
							<div style="margin-left:110px;margin-top:10px">
								<div class="layui-input-inline" style="width:200px">
									<input type="text" name="info[longitude]" id="mapjd" class="layui-input" value="{$info.longitude}"/>
								</div>
								<div class="layui-input-inline" style="width:200px">
									<input type="text" name="info[latitude]" id="mapwd" class="layui-input" value="{$info.latitude}"/>
								</div>
							</div>
						</div>
						{if getcustom('xixie')}
                            <div class="layui-form-item">
                                <label class="layui-form-label">余额：</label>
                                <div class="layui-input-inline" style="width:500px">
                                    <input type="text" id="money" name="info[money]" disabled="disabled" class="layui-input" value="{$info.money}">
                                </div>
                            </div>
							<div class="layui-form-item">
								<label class="layui-form-label">手续费：</label>
								<div class="layui-input-inline">
									<input type="text" id="withdrawfee" name="info[withdrawfee]" class="layui-input" value="{$info.withdrawfee}">
								</div>
                                <div class="layui-form-mid layui-word-aux" >%</div>
							</div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">最低提现金额：</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="withdrawmin" name="info[withdrawmin]" class="layui-input" value="{$info.withdrawmin}">
                                </div>
                                <div class="layui-form-mid layui-word-aux" ></div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">配送费：</label>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input style="border-radius:0 2px 2px 0"  type="text" name="info[peisong_juli1]" class="layui-input" value="{$info.peisong_juli1}">
                                </div>
                                <div class="layui-form-mid">公里内</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input style="border-radius:0 2px 2px 0"  type="text" name="info[peisong_fee1]" class="layui-input" value="{$info.peisong_fee1}">
                                </div>
                                <div class="layui-form-mid">元；每超出</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input style="border-radius:0 2px 2px 0"  type="text" name="info[peisong_juli2]" class="layui-input" value="{$info.peisong_juli2}">
                                </div>
                                <div class="layui-form-mid">公里，加</div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input style="border-radius:0 2px 2px 0"  type="text" name="info[peisong_fee2]" class="layui-input" value="{$info.peisong_fee2}">
                                </div>
                                <div class="layui-form-mid">元</div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">服务范围：</label>
                                <div class="layui-input-block" style="width:300px">
                                    <input type="radio" name="info[peisong_rangetype]"  value="0" title="圆形范围" {if !$info['id'] || $info['peisong_rangetype']==0}checked{/if} lay-filter="rangetypeset">
                                    <input type="radio" name="info[peisong_rangetype]"  value="1" title="多边形范围" {if $info['id'] && $info['peisong_rangetype']==1}checked{/if} lay-filter="rangetypeset">
                                </div>
                                <div class="form-group" style="margin-left:110px;padding-top:10px;padding-bottom:5px">
                                    <script src="https://webapi.amap.com/maps?v=1.4.0&key=cc6545949691fe61692f4036ab2f0336&plugin=AMap.PolyEditor,AMap.CircleEditor"></script>
                                    <div id="container" class="map" style="width:800px;height: 600px;"></div>
                                </div>
                                <div id="rangetypeset0" style="{if $info['id'] && $info['peisong_rangetype']==1}display:none{/if}">
                                    <div class="layui-form-mid" style="margin-left:100px;">中心点坐标</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="info[peisong_lng]"  class="layui-input" value="{$info.peisong_lng}">
                                    </div>
                                    <div class="layui-form-mid">,</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="info[peisong_lat]"  class="layui-input" value="{$info.peisong_lat}">
                                    </div>
                                    <div class="layui-form-mid">服务半径</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input type="text" name="info[peisong_range]"  class="layui-input" value="{$info.peisong_range}">
                                    </div>
                                    <div class="layui-form-mid">米</div>
                                </div>
                                <div id="rangetypeset1" style="{if !$info['id'] || $info['peisong_rangetype']==0}display:none{/if}">
                                    <input type="hidden" name="info[peisong_rangepath]" class="layui-input" value="{$info.peisong_rangepath}">
                                    <div class="layui-form-mid" style="margin-left:110px;">注：多边形的形状尽量简洁，不要有交叉线</div>
                                    <div class="layui-form-item">
                                        <label class="layui-form-label">服务点：</label>
                                        <div class="layui-input-inline" style="width:150px">
                                            <input type="text" name="info[peisong_lng2]" value="{$info['peisong_lng2']}" class="layui-input">
                                        </div>
                                        <div class="layui-form-mid">-</div>
                                        <div class="layui-input-inline" style="width:150px">
                                            <input type="text" name="info[peisong_lat2]" value="{$info['peisong_lat2']}" class="layui-input">
                                        </div>
                                        <button class="layui-btn layui-btn-primary" onclick="choosezuobiao()" style="float:left">选择坐标</button>
                                    </div>

                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"  style="width:100px">可预约时间：</label>
                                <div class="layui-input-inline" style="width:500px">
                                    <input type="radio" name="info[datetype]" value="1" title="时间段" {if !$info['datetype'] || $info['datetype']==1}checked{/if} lay-filter="datetype">
                                    <input type="radio" name="info[datetype]" value="2" title="时间点" {if $info['datetype']==2}checked{/if} lay-filter="datetype">
                                </div>
                            </div>
                            <div  id="datebox1" style="{if $info['datetype'] && $info['datetype']!=1}display:none{/if}">
                                <div class="layui-form-item">
                                    <label class="layui-form-label"  style="width:100px">设置时间段：</label>
                                    <div class="layui-form-mid">早</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input style="border-radius:0 2px 2px 0" type="text" name="info[zaohour]" class="layui-input" value="{$info.zaohour?$info.zaohour:'7'}">
                                    </div>
                                    <div class="layui-form-mid">时；晚</div>
                                    <div class="layui-input-inline" style="width: 100px;">
                                        <input style="border-radius:0 2px 2px 0" type="text" name="info[wanhour]" class="layui-input" value="{$info.wanhour?$info.wanhour:'18'}">
                                    </div>
                                    <div class="layui-form-mid">时</div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label"  style="width:100px">时间间隔：</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="info[timejg]" value="{$info['id']?$info['timejg']:'30'}" class="layui-input">
                                    </div>
                                        <div class="layui-form-mid layui-word-aux">分钟</div>
                                </div>
                            </div>
                            <div  id="datebox2" style="{if $info['datetype']!=2}display:none{/if}">
                                {if $info['datetype']==2 && $info['timepoint']}
                                <div id="timedata">
                                    {foreach $info['timepoint'] as $k=>$t}
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"  style="width:100px">{if $k==0}选择时间点：{/if}</label>                                      
                                            <div class="layui-input-inline">
                                                <input type="text" name="info[timepoint][]" value="{$t}"  class="layui-input timepoint">    
                                            </div>
                                            {if $k==0}
                                            <button class="layui-btn layui-btn-primary" onclick="addtime()"><i class="fa fa-plus"></i></button>
                                            {else}
                                            <button class="layui-btn layui-btn-primary" onclick="removetime(this)"><i class="fa fa-minus"></i></button>
                                            {/if}
                                    </div>
                                    {/foreach}
                                </div>
                                {else}
                                <div id="timedata">
                                    <div class="layui-form-item">
                                        <label class="layui-form-label"  style="width:100px">选择时间点：</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="info[timepoint][]" value="00:00"  class="layui-input timepoint">   
                                        </div>
                                        {if $k==0}
                                        <button class="layui-btn layui-btn-primary" onclick="addtime()"><i class="fa fa-plus"></i></button>
                                        {else}
                                        <button class="layui-btn layui-btn-primary" onclick="removetime(this)"><i class="fa fa-minus"></i></button>
                                        {/if}
                                    </div>
                                </div>  
                                {/if}
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label"  style="width:100px">预约人数：</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="info[yynum]" value="{$info['id']?$info['yynum']:'1'}" class="layui-input">
                                </div>
                                    <div class="layui-form-mid layui-word-aux">同一时间预约人数限制，默认为1</div>
                            </div>
                            <div class="layui-form-item"  >
                                    <label class="layui-form-label"  style="width:100px">可预约日期：</label>
                                    <div class="layui-input-inline" style="width:500px">
                                        <input type="radio" name="info[rqtype]" value="1" title="按周期" {if !$info['rqtype'] || $info['rqtype']==1}checked{/if} lay-filter="rqtype">
                                        <input type="radio" name="info[rqtype]" value="2" title="按时间" {if $info['rqtype']==2}checked{/if} lay-filter="rqtype">                      
                                        <input type="radio" name="info[rqtype]" value="3" title="按固定周期" {if $info['rqtype']==3}checked{/if} lay-filter="rqtype">
                                    </div>
                                </div>
                                <div class="layui-form-item"  id="yydatebox1" style="{if $info['rqtype'] && $info['rqtype']!=1}display:none{/if}">
                                    <label class="layui-form-label"  style="width:100px">预约周期：</label>
                                    <div class="layui-input-inline" style="width:600px">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(1,$info['yyzhouqi'])}checked{/if} value="1"  title="周一" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(2,$info['yyzhouqi'])}checked{/if} value="2"  title="周二" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(3,$info['yyzhouqi'])}checked{/if} value="3"  title="周三" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(4,$info['yyzhouqi'])}checked{/if} value="4"  title="周四" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(5,$info['yyzhouqi'])}checked{/if} value="5"  title="周五" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(6,$info['yyzhouqi'])}checked{/if} value="6"  title="周六" lay-skin="primary">
                                            <input type="checkbox" name="info[yyzhouqi][]" {if in_array(0,$info['yyzhouqi'])}checked{/if} value="0"  title="周日" lay-skin="primary">
                                    </div>
                                    <!-- <div class="layui-form-mid layui-word-aux"><a href="groupadd.php">创建分组</a></div> -->
                                </div>
                                <div class="layui-form-item"  id="yydatebox2" style="{if $info['rqtype']!=2}display:none{/if}">
                                    <label class="layui-form-label"  style="width:100px">选择日期：</label>
                                    <div class="layui-input-inline" style="width:600px">
                                        <div class="layui-input-inline" style="width:150px">
                                            <input type="text" name="info[yybegintime]" class="layui-input" value="{$info.yybegintime}" id="yybegintime" autocomplete="off">
                                        </div>
                                        <div class="layui-form-mid">到</div>
                                        <div class="layui-input-inline" style="width:150px">
                                            <input type="text" name="info[yyendtime]" class="layui-input" value="{$info.yyendtime}" id="yyendtime" autocomplete="off">
                                        </div>
                                        <div class="layui-form-mid layui-word-aux" style="clear:left;margin-left:110px"></div>  
                                    </div>
                                    <!-- <div class="layui-form-mid layui-word-aux"><a href="groupadd.php">创建分组</a></div> -->
                                </div>


                                <div class="layui-form-item"  id="yydatebox3" style="{if $info['rqtype']!=3}display:none{/if}">
                                    <div id="pstimedata">
                                        {foreach $info[yytimeday] as $k=>$v}
                                        <div class="layui-form-item">   

                                            <label class="layui-form-label" style="width:100px">{if $k==0}选择日期：{/if}</label>
                                            <div class="layui-input-inline" style="width:120px">
                                                <select name="info[timeday][]"  >
                                                    <option value="1" {if $v==1}selected{/if}>当天</option>
                                                    {for start="2" end="8"}
                                                    <option value="{$i}" {if $v==$i}selected{/if}>第{$i}天</option>
                                                    {/for}
                                                </select>
                                            </div>  
                                            {if $k==0}
                                            <button class="layui-btn layui-btn-primary" onclick="adddaytime()"><i class="fa fa-plus"></i></button>
                                            {else}
                                            <button class="layui-btn layui-btn-primary" onclick="removedaytime(this)"><i class="fa fa-minus"></i></button>
                                            {/if}
                                        </div>
                                        {/foreach}
                                    </div>
                                    <!-- <div class="layui-form-mid layui-word-aux"><a href="groupadd.php">创建分组</a></div> -->
                                </div>
                                <script>
                                    function adddaytime(){
                                        var html = '';
                                        html+='<div class="layui-form-item">';
                                        html+=' <label class="layui-form-label" style="width:100px"></label>';
                                        html+=' <div class="layui-input-inline" style="width:120px">';
                                        html+='     <select name="info[timeday][]">';
                                        html+='         <option value="1">当天</option>';
                                        {for start="2" end="8"}
                                        html+='         <option value="{$i}">第{$i}天</option>';
                                        {/for}
                                        html+='     </select>';
                                        html+=' </div>';
                                        html+=' <button class="layui-btn layui-btn-primary" onclick="removedaytime(this)"><i class="fa fa-minus"></i></button>';
                                        html+='</div>';
                                        $('#pstimedata').append(html);
                                        layui.form.render();
                                    }
                                    function removedaytime(obj){
                                        $(obj).parent().remove();
                                    }
                                </script>
                                <div class="layui-form-item">
                                    <label class="layui-form-label"  style="width:100px">可选条件：</label>
                                    <div class="layui-form-mid">下单时间大于可选时间</div>
                                    <div class="layui-input-inline" style="width:70px">
                                        <input type="text" name="info[pdprehour]" value="{if !$info['id']}4{else}{$info['pdprehour']}{/if}" class="layui-input">
                                    </div>
                                    <div class="layui-form-mid">小时</div>
                                </div>
						{/if}
						<div class="layui-form-item">
							<label class="layui-form-label">序号：</label>
							<div class="layui-input-inline">
								<input type="text" name="info[sort]" value="{$info.sort|default=0}" class="layui-input">
							</div>
							<div class="layui-form-mid layui-word-aux" style="margin-left:10px;">用于排序,越大越靠前</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">状态：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[status]" value="1" title="开启" {if !$info['id'] || $info['status']==1}checked{/if}>
								<input type="radio" name="info[status]" value="0" title="关闭" {if $info['id'] && $info['status']==0}checked{/if}>
							</div>
						</div>
						{if getcustom('mendian_hexiao_givemoney')}
						<div class="layui-form-item">
							<label class="layui-form-label">核销提成：</label>
							<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">提成比例(%)</div>
							<div class="layui-input-inline" style="width:120px">
								<input type="text" id="hexiaogivepercent" name="info[hexiaogivepercent]" class="layui-input" value="{$info.hexiaogivepercent|default='0'}">
							</div>
							<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">提成金额(元)</div>
							<div class="layui-input-inline" style="width:120px">
								<input type="text" id="hexiaogivemoney" name="info[hexiaogivemoney]" class="layui-input" value="{$info.hexiaogivemoney|default='0'}">
							</div>
							<div class="layui-form-mid" style="margin-right:0;background:#e6e6e6;padding: 9px 9px !important">提现手续费(%)</div>
							<div class="layui-input-inline" style="width:120px">
								<input type="text" id="withdrawfee" name="info[withdrawfee]" class="layui-input" value="{$info.withdrawfee|default='0'}">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label">多商户是否可用：</label>
							<div class="layui-input-inline">
								<input type="radio" name="info[business_canuse]" value="1" title="是" {if $info['business_canuse']==1}checked{/if}>
								<input type="radio" name="info[business_canuse]" value="0" title="否" {if !$info['id'] || $info['business_canuse']==0}checked{/if}>
							</div>
						</div>
						{/if}

						<div class="layui-form-item">
							<div class="layui-input-block">
								<button class="layui-btn layui-btn-danger" lay-submit lay-filter="formsubmit">提 交</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
	{include file="public/js"/}
	<script charset="utf-8" src="https://map.qq.com/api/js?v=2.exp&key=ABLBZ-4BIKU-GFTVB-BK7IK-OLQ35-QCBFF"></script>
	<script>
    function addtime(){
        var html = '';
        html+='<div class="layui-form-item">';
        html+=' <label class="layui-form-label"  style="width:100px"></label>';
        html+=' <div class="layui-input-inline">';
        html+='     <input type="text" name="info[timepoint][]" value="2021-09-27" class="layui-input timepoint">   ';
        html+=' </div>';
        html+=' <button class="layui-btn layui-btn-primary" onclick="removetime(this)"><i class="fa fa-minus"></i></button>';
        html+='</div>';
        $('#timedata').append(html);
        layui.form.render();

        $('.timepoint').each(function() {
            layui.laydate.render({elem:this,type: 'time',trigger: 'click',format:'HH:mm' });
        });

    }
    function removetime(obj){
        $(obj).parent().remove();
    }
    $('.timepoint').each(function() {
        layui.laydate.render({elem:this,type: 'time',trigger: 'click',format:'HH:mm' });
    });
    layui.laydate.render({ 
        elem: '#start_time',
        type: 'datetime',
        trigger: 'click'
    });
    layui.laydate.render({ 
        elem: '#end_time',
        type: 'datetime',
        trigger: 'click'
    });
    layui.laydate.render({ 
        elem: '#yybegintime',
        type: 'date',
        trigger: 'click'
    });
    layui.laydate.render({ 
        elem: '#yyendtime',
        type: 'date',
        trigger: 'click'
    });
    layui.form.on('radio(datetype)', function(data){
        if(data.value == '1'){
            $('#datebox2').hide();
            $('#datebox1').show();
        }else{
            $('#datebox2').show();
            $('#datebox1').hide();
        }
    })
    layui.form.on('radio(rqtype)', function(data){
        if(data.value == '1'){
            $('#yydatebox2').hide();
            $('#yydatebox3').hide();
            $('#yydatebox1').show();
        }else if(data.value == '2'){
            $('#yydatebox2').show();
            $('#yydatebox1').hide();
            $('#yydatebox3').hide();
        }else if(data.value == '3'){
            $('#yydatebox2').hide();
            $('#yydatebox1').hide();
            $('#yydatebox3').show();
        }
    })
	var ueditor = UE.getEditor('content');
	layui.form.on('submit(formsubmit)', function(obj){
		var field = obj.field
		field['info[content]'] = ueditor.getContent();
		//console.log(field);return;
		var index = layer.load();
		$.post("{:url('save')}",field,function(data){
			layer.close(index);
			dialog(data.msg,data.status);
			if(data.status == 1){
				setTimeout(function(){
					parent.layer.close(parent.layer.getFrameIndex(window.name));
					parent.tableIns.reload()
				},1000)
			}
		})
	})

  	</script>
  	<script type="text/javascript">
  		function choosezuobiao(){
        var address = '';
        var longitude = $("input[name='info[peisong_lng2]']").val();
        var latitude = $("input[name='info[peisong_lat2]']").val();
        if(!longitude){
            longitude = $("input[name='info[peisong_lng]']").val();
            latitude = $("input[name='info[peisong_lat]']").val();
        }
        var choosezblayer = layer.open({type:2,shadeClose: true,area: ['800px', '560px'],'title': '选择坐标',content: "{:url('DesignerPage/choosezuobiao')}&address="+(address?address:"")+"&jd="+(longitude?longitude:"")+"&wd="+(latitude?latitude:""),btn:['确定','取消'],yes:function(index, layero){
            var longitude = layero.find('iframe').contents().find('#mapjd').val();
            var latitude = layero.find('iframe').contents().find('#mapwd').val();
            $("input[name='info[peisong_lng2]']").val(longitude);
            $("input[name='info[peisong_lat2]']").val(latitude);
            layer.close(choosezblayer);
        }});
    }

    var lng = $("input[name='info[peisong_lng]']").val();
    var lat = $("input[name='info[peisong_lat]']").val();
    var range = $("input[name='info[peisong_range]']").val();
    var rangetype = '{$info.peisong_rangetype}';
    var rangepath = $("input[name='info[peisong_rangepath]']").val();
    var lnglat = '';//设置的坐标
    if(lng !="" && lat !=""){ 
        lng = parseFloat(lng);
        lat = parseFloat(lat);
        lnglat=[lng,lat];
    }
    if(range==0){ range=2000;}
    layui.form.on('radio(rangetypeset)',function(data){
        if(data.value == '0'){
            $('#rangetypeset0').show();
            $('#rangetypeset1').hide();
            addcircle();
        }else{
            $('#rangetypeset0').hide();
            $('#rangetypeset1').show();
            addpoly();
        }
    })
    //初始化地图参数
    var map = new AMap.Map("container", {
        resizeEnable: true,//是否监控地图容器尺寸变化，默认值为false
        dragEnable: true,//是否允许拖拽地图
        keyboardEnable: false,//是否允许键盘平移
        doubleClickZoom: false,//是否允许双击放大地图
        scrollWheel:true,//是否允许鼠标滚轮操作地图
        center:lnglat,
        zoom: 13 //地图显示的缩放级别
    });

    var mapcenter = map.getCenter();
    var lng = mapcenter.lng
    var lat = mapcenter.lat
    lnglat = [lng,lat];
    $("input[name='info[peisong_lng]']").val(lng);
    $("input[name='info[peisong_lat]']").val(lat);
    $("input[name='info[peisong_range]']").val(range);

    if(!rangepath){
        var key = 0.02;
        rangepath = [
            [lng - key, lat - key],
            [lng + key, lat - key],
            [lng + key, lat + key],
            [lng - key, lat + key]
        ];
    }else{
        rangepathdata = rangepath.split(';');
        rangepath = [];
        for(var i in rangepathdata){
            var path = rangepathdata[i].split(',');
            rangepath.push([path[0],path[1]]);
        }
        console.log(rangepath);
    }
    if(rangetype==0 ){
        addcircle();
    }else{
        addpoly();
    }
    function addcircle(){
        map.clearMap();
        var circlegon = new AMap.Circle({
            center: lnglat,// 圆心位置
            radius: range, //半径
            strokeColor: "#4e73f1", //线颜色
            strokeOpacity: 1, //线透明度
            strokeWeight: 3, //线粗细度
            fillColor: "#4e73f1", //填充颜色
            fillOpacity: 0.35,//填充透明度
        });

        map.add(circlegon)
        map.setFitView([circlegon]);
        {if in_array('hmy_yuyue',getcustom())  && ($bid>0)}
            return;
        {/if}
        var circleEditor= new AMap.CircleEditor(map,circlegon);
        circleEditor.open(lnglat);
        
        circleEditor.on('move', function (event) {
            $("input[name='info[peisong_lng]']").val(event.lnglat.lng);
            $("input[name='info[peisong_lat]']").val(event.lnglat.lat);
        });
        circleEditor.on('adjust', function (event) {
            $("input[name='info[peisong_range]']").val(event.radius);
        });
    }
    function addpoly(){
        map.clearMap();
        var polygon = new AMap.Polygon({
            path: rangepath,
            strokeColor: "#FF33FF",
            strokeOpacity: 0.2,
            fillOpacity: 0.4,
            fillColor: '#1791fc',
            zIndex: 50,
            draggable:true
        });
        map.add(polygon)
        map.setFitView([polygon])
        var polyEditor = new AMap.PolyEditor(map, polygon);
        polyEditor.open();
        setpathvalue(polygon);
        polyEditor.on('addnode', function (event) {
            console.log('触发事件：addnode')
            setpathvalue(polygon);
        });
        polyEditor.on('adjust', function (event) {
            console.log('触发事件：adjust');
            setpathvalue(polygon);
        });
        polyEditor.on('removenode', function (event) {
            console.log('触发事件：removenode')
            setpathvalue(polygon);
        });
        polyEditor.on('end', function (event) {
            console.log('触发事件： end')
            setpathvalue(polygon);
        });
        polygon.on('change', function (event) {
            console.log('polygon触发事件： change')
            setpathvalue(polygon);
        });
    }
    function setpathvalue(polygon){
        var pathdata = polygon.getPath();
        var pathArr = [];
        for(var i in pathdata){
            pathArr.push(pathdata[i].lng +','+pathdata[i].lat);
        }
        $("input[name='info[peisong_rangepath]']").val(pathArr.join(';'));
    }
  	</script>
	<script>

	var searchService, map,markers = [],marker = null,citylocation;
	var jd = $('#mapjd').val();
	var wd = $('#mapwd').val();
	window.onload=function(){
		function init(){
			if(!jd || !wd){
				var center = new qq.maps.LatLng(39.90358020251377,116.39782905578613);
			}else{
				var center = new qq.maps.LatLng(wd,jd);
			}
			var map = new qq.maps.Map(document.getElementById("l-map"), {
				center: center,      // 地图的中心地理坐标。
				zoom:15              // 地图的中心地理坐标。
			});	
			console.log(center);
			if(!jd || !wd){
				//获取城市列表接口设置中心点
				citylocation = new qq.maps.CityService({
					complete : function(result){
						map.setCenter(result.detail.latLng);
					}
				});
				citylocation.searchLocalCity();
			}
			var marker = new qq.maps.Marker({ position:center, map: map});
			markers.push(marker);
			 //绑定单击事件添加参数
			qq.maps.event.addListener(map, 'click', function(event) {
				clearOverlays(markers);
				$("#mapjd").val(event.latLng.getLng());
				$("#mapwd").val(event.latLng.getLat());
				var marker = new qq.maps.Marker({ position: new qq.maps.LatLng(event.latLng.getLat(), event.latLng.getLng()) , map: map
				});
				markers.push(marker);
			});
			//设置Poi检索服务，用于本地检索、周边检索
			searchService = new qq.maps.SearchService({
				//设置搜索范围为北京
				location: center.lat+"," +center.lng,
				//设置搜索页码为1
				pageIndex: 1,
				//设置每页的结果数为5
				pageCapacity: 5,
				//设置展现查询结构到infoDIV上
				// panel: document.getElementById('infoDiv'),
				//设置动扩大检索区域。默认值true，会自动检索指定城市以外区域。
				autoExtend: true,
				//检索成功的回调函数
				complete: function(results) {
					//设置回调函数参数
					var pois = results.detail.pois;
					var infoWin = new qq.maps.InfoWindow({
						map: map
					});
					var latlngBounds = new qq.maps.LatLngBounds();
					for (var i = 0, l = pois.length; i < l; i++) {
						var poi = pois[i];
						//扩展边界范围，用来包含搜索到的Poi点
						latlngBounds.extend(poi.latLng);
						(function(n) {
							var marker = new qq.maps.Marker({
								map: map
							});
							marker.setPosition(pois[n].latLng);
							marker.setTitle(i + 1);
							markers.push(marker);
							qq.maps.event.addListener(marker, 'click', function() {
								$("#mapjd").val(pois[n].latLng.lng);
								$("#mapwd").val(pois[n].latLng.lat);
								infoWin.setPosition(pois[n].latLng);
							});
						})(i);
					}
					//调整地图视野
					map.fitBounds(latlngBounds);
				},
				//若服务请求失败，则运行以下函数
				error: function() {
					dialog("请先搜索省市区再搜索详细地址");
				}
			});
		}
		init();
	}
	//清除地图上的marker
    function clearOverlays(overlays) {
        var overlay;
        while (overlay = overlays.pop()) {
            overlay.setMap(null);
        }
    }
	$("#searchbtn").click(function(){
		var address = $("#address").val();
		if(address == ""){
			dialog("请输地址！");
			return ;
		}
		 clearOverlays(markers);
		//根据输入的关键字在搜索范围内检索
    	searchService.search(address);
	});
	</script>
	{include file="public/copyright"/}
</body>
</html>